package org.personal.struts.interceptor;

import org.apache.struts2.ServletActionContext;
import org.personal.struts.action.DefaultAction;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;

public class ActionSuffixInterceptor implements com.opensymphony.xwork2.interceptor.Interceptor {

	private static final long serialVersionUID = -1656884753845346981L;

	private String root="";
	private String jsp="";
	private String html="";
	
	public void destroy(){}

	public void init(){}

	public String intercept(ActionInvocation invocation)throws Exception {
		System.out.println("Session:"+ServletActionContext.getRequest().getSession().getId());
		String result=Action.SUCCESS;
		//获得Action
		Object action = invocation.getAction();
		//如果请求的DefaultAction,表示没有找到对应Action请求的配置信息
		if(action.getClass().isAssignableFrom(DefaultAction.class)){
			DefaultAction defaultAction = (DefaultAction)action;
			defaultAction.setRoot(root);
			defaultAction.setJsp(jsp);
			defaultAction.setHtml(html);
			result=defaultAction.execute();
		}else{
			result=invocation.invoke();
		}
		return result;
	}
	
	public void setRoot(String root) {
		this.root = root;
	}

	public void setJsp(String jsp) {
		this.jsp = jsp;
	}

	public void setHtml(String html) {
		this.html = html;
	}
}
